package o;

import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;
import androidx.annotation.NonNull;
import o.yf.c;

final class yk implements yf {
    private boolean ˊ;
    boolean ˋ;
    private final BroadcastReceiver ˎ = new BroadcastReceiver(this) {
        final /* synthetic */ yk ˊ;

        {
            this.ˊ = r1;
        }

        public void onReceive(@NonNull Context context, Intent intent) {
            boolean z = this.ˊ.ˋ;
            this.ˊ.ˋ = this.ˊ.ˊ(context);
            if (z != this.ˊ.ˋ) {
                if (Log.isLoggable("ConnectivityMonitor", 3)) {
                    Log.d("ConnectivityMonitor", "connectivity changed, isConnected: " + this.ˊ.ˋ);
                }
                this.ˊ.ॱ.ˏ(this.ˊ.ˋ);
            }
        }
    };
    private final Context ˏ;
    final c ॱ;

    yk(@NonNull Context context, @NonNull c cVar) {
        this.ˏ = context.getApplicationContext();
        this.ॱ = cVar;
    }

    private void ˋ() {
        if (!this.ˊ) {
            this.ˋ = ˊ(this.ˏ);
            try {
                this.ˏ.registerReceiver(this.ˎ, new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE"));
                this.ˊ = true;
            } catch (Throwable e) {
                if (Log.isLoggable("ConnectivityMonitor", 5)) {
                    Log.w("ConnectivityMonitor", "Failed to register", e);
                }
            }
        }
    }

    private void ॱ() {
        if (this.ˊ) {
            this.ˏ.unregisterReceiver(this.ˎ);
            this.ˊ = false;
        }
    }

    @SuppressLint({"MissingPermission"})
    boolean ˊ(@NonNull Context context) {
        try {
            NetworkInfo activeNetworkInfo = ((ConnectivityManager) aas.ˎ((ConnectivityManager) context.getSystemService("connectivity"))).getActiveNetworkInfo();
            if (activeNetworkInfo == null || !activeNetworkInfo.isConnected()) {
                return false;
            }
            return true;
        } catch (Throwable e) {
            if (Log.isLoggable("ConnectivityMonitor", 5)) {
                Log.w("ConnectivityMonitor", "Failed to determine connectivity status when connectivity changed", e);
            }
            return true;
        }
    }

    public void onStart() {
        ˋ();
    }

    public void onStop() {
        ॱ();
    }

    public void onDestroy() {
    }
}
